/*
 *  AbstractLineTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/10/03.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "AbstractLineTester.h"
#include "../../../sc/Tester/CustomAssert.h"

#include "../AbstractNote.h"
#include "../AbstractLine.h"
#include "../ConcreteLine.h"

namespace sc
{
namespace system0039
{

	void AbstractLineTester::TestAll()
	{
		Test_GetConcreteLines000();
		Test_GetConcreteLines001();
		Test_GetConcreteLines002();
		Test_GetConcreteLines003();
	}

	void AbstractLineTester::Test_GetConcreteLines000()
	{
		AbstractLine line;
		line.AddNote( AbstractNote( Note::D1, Note::E2, Note::mezzoPiano ) );
		
		std::vector< ConcreteLine > lines;
		line.GetConcreteLines( lines );

		AssertEqual( lines.size(), 2 );

		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::E2 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 1 ), 2 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::E2 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
	}

	void AbstractLineTester::Test_GetConcreteLines001()
	{
		AbstractLine line;
		line.AddNote( AbstractNote( Note::DSharp1, Note::DSharp3, Note::mezzoPiano ) );

		std::vector< ConcreteLine > lines;
		line.GetConcreteLines( lines );
		
		AssertEqual( lines.size(), 2 );

		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::DSharp3 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::DSharp1 );

		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::DSharp3 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::DSharp1 );
	}
	
	void AbstractLineTester::Test_GetConcreteLines002()
	{
		AbstractLine line;
		line.AddNote( AbstractNote( Note::D1, Note::B2, Note::mezzoPiano ) );
		line.AddNote( AbstractNote( Note::D1, Note::D3, Note::mezzoPiano ) );

		std::vector< ConcreteLine > lines;
		line.GetConcreteLines( lines );
		
		AssertEqual( lines.size(), 4 );

		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 2 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 2 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 2 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 2 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 3 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 3 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 3 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 3 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
	}

	void AbstractLineTester::Test_GetConcreteLines003()
	{
		AbstractLine line;
		line.AddNote( AbstractNote( Note::D1, Note::B2, Note::mezzoPiano ) );
		line.AddNote( AbstractNote( Note::D1, Note::FSharp3, Note::mezzoPiano ) );
		line.AddNote( AbstractNote( Note::D1, Note::D3, Note::mezzoPiano ) );

		std::vector< ConcreteLine > lines;
		line.GetConcreteLines( lines );
		
		AssertEqual( lines.size(), 12 );

		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 0 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 0 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 0 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 0 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 0 ].at( 2 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 0 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 1 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 1 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 1 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 1 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 1 ].at( 2 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 1 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 2 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 2 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 2 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 2 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 2 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 2 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 2 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 2 ].at( 2 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 2 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 3 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 3 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 3 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 3 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 3 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 3 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 3 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 3 ].at( 2 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 3 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 4 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 4 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 4 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 4 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 4 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 4 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 4 ].at( 1 ).GetNthHarmonics( 1 ), 6 );
		AssertEqual( lines[ 4 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 4 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 4 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 4 ].at( 2 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 4 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 5 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 5 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 5 ].at( 0 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 5 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 5 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 5 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 5 ].at( 1 ).GetNthHarmonics( 1 ), 6 );
		AssertEqual( lines[ 5 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 5 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 5 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 5 ].at( 2 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 5 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 6 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 6 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 6 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 6 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 6 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 6 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 6 ].at( 1 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 6 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 6 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 6 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 6 ].at( 2 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 6 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 7 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 7 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 7 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 7 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 7 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 7 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 7 ].at( 1 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 7 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 7 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 7 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 7 ].at( 2 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 7 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 8 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 8 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 8 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 8 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 8 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 8 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 8 ].at( 1 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 8 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 8 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 8 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 8 ].at( 2 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 8 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 9 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 9 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 9 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 9 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 9 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 9 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 9 ].at( 1 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 9 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 9 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 9 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 9 ].at( 2 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 9 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 10 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 10 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 10 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 10 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 10 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 10 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 10 ].at( 1 ).GetNthHarmonics( 1 ), 6 );
		AssertEqual( lines[ 10 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 10 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 10 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 10 ].at( 2 ).GetNthHarmonics( 1 ), 3 );
		AssertEqual( lines[ 10 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

		AssertEqual( lines[ 11 ].at( 0 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 11 ].at( 0 ).GetNoteMidiNumber( 0 ), Note::B2 );
		AssertEqual( lines[ 11 ].at( 0 ).GetNthHarmonics( 1 ), 4 );
		AssertEqual( lines[ 11 ].at( 0 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 11 ].at( 1 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 11 ].at( 1 ).GetNoteMidiNumber( 0 ), Note::FSharp3 );
		AssertEqual( lines[ 11 ].at( 1 ).GetNthHarmonics( 1 ), 6 );
		AssertEqual( lines[ 11 ].at( 1 ).GetNoteMidiNumber( 1 ), Note::D1 );
		AssertEqual( lines[ 11 ].at( 2 ).GetNthHarmonics( 0 ), 1 );
		AssertEqual( lines[ 11 ].at( 2 ).GetNoteMidiNumber( 0 ), Note::D3 );
		AssertEqual( lines[ 11 ].at( 2 ).GetNthHarmonics( 1 ), 5 );
		AssertEqual( lines[ 11 ].at( 2 ).GetNoteMidiNumber( 1 ), Note::D1 );

	}

}
}
